﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_sub_menu_fv.ascx.vb"
    Inherits="Apps_Shares_Uc_sub_menu_fv" %>
<asp:HiddenField ID='hideMenuSystemCode' runat='server' Value='' />
<asp:FormView ID="fv" runat="server" DefaultMode="Insert" RenderOuterTable="False"
    Width="100%" DataSourceID="fvSrc">
    <InsertItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูย่อยระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtSubMenuName' runat='server' CssClass='text_normal' Text='<%# Bind("sub_menu_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlSystem' runat='server' SelectedValue='<%# Bind("main_system_code") %>'
                            DataSourceID="ddlSystemSrc" DataTextField="main_system_name"
                            DataValueField="main_system_code" AutoPostBack="True">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlSystemSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand=" SELECT 0 [main_system_code], 'ระบบ' [main_system_name] 
                                            UNION ALL
                                            SELECT [main_system_code], [main_system_name] FROM [stp_main_system] WHERE ([main_system_status] = @main_system_status) and  main_system_type > 0 ">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="main_system_status" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlMenu' runat='server' AutoPostBack='true' DataSourceID="ddlMenuSrc"
                            DataTextField="menu_system_name" DataValueField="menu_system_code">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlMenuSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand="
                                SELECT 0 [menu_system_code], 'เมนูระบบ'[menu_system_name]
                                UNION ALL 
                                SELECT  [menu_system_code], 
                                        [menu_system_name] 
                                FROM    [stp_menu_system] 
                                WHERE   [menu_system_status] = @menu_system_status 
                                        and main_system_code = @main_system_code ">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="menu_system_status" Type="Int32" />
                                <asp:ControlParameter ControlID="ddlSystem" DefaultValue="0" Name="main_system_code"
                                    PropertyName="SelectedValue" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภทการทำงาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlType' runat='server' SelectedValue='<%# Bind("type_code") %>'
                            DataSourceID="ddlTypeSrc" DataTextField="type_name" DataValueField="type_code">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlTypeSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand=" SELECT 0 [type_code], 'ประเภทการทำงาน' [type_name]
                                            UNION ALL
                                            SELECT [type_code], [type_name] FROM [master_type] WHERE ([type_status] = @type_status)">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="type_status" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        URL <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtURL' runat='server' CssClass='text_normal' Text='<%# Bind("sub_menu_url") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' SelectedValue='<%# Bind("sub_menu_status") %>'
                            RepeatDirection="Horizontal" RepeatLayout="Flow">
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Insert" ValidationGroup="g1" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtSubMenuNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtSubMenuName" ErrorMessage="กรุณากรอกชือเมนูย่อยระบบ" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlSystemRequiredFieldValidator" runat="server" ControlToValidate="ddlSystem"
                                ErrorMessage="กรุณาเลือกระบบ" InitialValue="0" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlMenuRequiredFieldValidator" runat="server" ControlToValidate="ddlMenu"
                                ErrorMessage="กรุณาเลือกเมนูระบบ" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlTypeRequiredFieldValidator" runat="server" ControlToValidate="ddlType"
                                ErrorMessage="กรุณาเลือกประเภทการทำงาน" InitialValue="0" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="txtURLRequiredFieldValidator" runat="server" ControlToValidate="txtURL"
                                ErrorMessage="กรุณากรอก URL ของเมนูย่อยระบบ" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ValidationGroup="g1"
                                ShowMessageBox='true' />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </InsertItemTemplate>
    <EditItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูย่อยระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtSubMenuName' runat='server' CssClass='text_normal' Text='<%# Bind("sub_menu_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlSystem' runat='server' SelectedValue='<%# Bind("main_system_code") %>'
                            DataSourceID="ddlSystemSrc" DataTextField="main_system_name" DataValueField="main_system_code"
                            AutoPostBack="True">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlSystemSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand="SELECT [main_system_code], [main_system_name] FROM [stp_main_system] WHERE ([main_system_status] = @main_system_status) and  main_system_type > 0 ">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="main_system_status" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlMenu' runat='server' SelectedValue='<%# Bind("menu_system_code") %>'
                            DataSourceID="ddlMenuSrc" DataTextField="menu_system_name" DataValueField="menu_system_code">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlMenuSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand="
                                SELECT  [menu_system_code], 
                                        [menu_system_name] 
                                FROM    [stp_menu_system] 
                                WHERE   [menu_system_status] = @menu_system_status  
                                        and main_system_code = @main_system_code">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="menu_system_status" Type="Int32" />
                                <asp:ControlParameter ControlID="ddlSystem" DefaultValue="0" Name="main_system_code"
                                    PropertyName="SelectedValue" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภทการทำงาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlType' runat='server' SelectedValue='<%# Bind("type_code") %>'
                            DataSourceID="ddlTypeSrc" DataTextField="type_name" DataValueField="type_code">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlTypeSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand="SELECT [type_code], [type_name] FROM [master_type] WHERE ([type_status] = @type_status)">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="1" Name="type_status" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        URL <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtURL' runat='server' CssClass='text_normal' Text='<%# Bind("sub_menu_url") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' SelectedValue='<%# Bind("sub_menu_status") %>'
                            RepeatDirection="Horizontal" RepeatLayout="Flow">
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Update" ValidationGroup="g1" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtSubMenuNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtSubMenuName" ErrorMessage="กรุณากรอกชือเมนูย่อยระบบ" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlSystemRequiredFieldValidator" runat="server" ControlToValidate="ddlSystem"
                                ErrorMessage="กรุณาเลือกระบบ" InitialValue="0" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlMenuRequiredFieldValidator" runat="server" ControlToValidate="ddlMenu"
                                ErrorMessage="กรุณาเลือกเมนูระบบ" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlTypeRequiredFieldValidator" runat="server" ControlToValidate="ddlType"
                                ErrorMessage="กรุณาเลือกประเภทการทำงาน" InitialValue="0" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="txtURLRequiredFieldValidator" runat="server" ControlToValidate="txtURL"
                                ErrorMessage="กรุณากรอก URL ของเมนูย่อยระบบ" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ValidationGroup="g1"
                                ShowMessageBox='true' />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="fvSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
    SelectCommand="
        select * , 
        Creator = dbo.UFN_GetAuditor(staff_code_create,create_datetime) , 
        Editor = dbo.UFN_GetAuditor(staff_code_update,update_datetime)
        from stp_sub_menu 
        where sub_menu_code = @sub_menu_code" 
    InsertCommand="
        INSERT INTO [stp_sub_menu]
           ([main_system_code]
           ,[menu_system_code]
           ,[sub_menu_name]
           ,[sub_menu_url]
           ,[type_code]
           ,[sub_menu_status]
           ,[staff_code_create]
           ,[create_datetime]
           ,[staff_code_update]
           ,[update_datetime])
        VALUES
           (@main_system_code
           ,@menu_system_code
           ,@sub_menu_name
           ,@sub_menu_url
           ,@type_code
           ,@sub_menu_status
           ,@staff_code_create
           ,getdate()
           ,@staff_code_update
           ,getdate())" 
    UpdateCommand="UPDATE [stp_sub_menu]
        SET   [menu_system_code] = @menu_system_code
              ,[sub_menu_name] = @sub_menu_name
              ,[sub_menu_url] = @sub_menu_url
              ,[type_code] = @type_code
              ,[sub_menu_status] = @sub_menu_status
              ,[staff_code_update] = @staff_code_update
              ,[update_datetime] = @update_datetime
        WHERE sub_menu_code = @sub_menu_code;">
    <SelectParameters>
        <asp:QueryStringParameter Name="sub_menu_code" QueryStringField="Edit" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="menu_system_code" />
        <asp:Parameter Name="sub_menu_name" />
        <asp:Parameter Name="sub_menu_url" />
        <asp:Parameter Name="type_code" />
        <asp:Parameter Name="sub_menu_status" />
        <asp:SessionParameter Name="staff_code_update" SessionField="staff_code" />
        <asp:Parameter Name="update_datetime" />
        <asp:QueryStringParameter Name="sub_menu_code" QueryStringField="Edit" />
    </UpdateParameters>
    <InsertParameters>
        <asp:ControlParameter ControlID='hideMenuSystemCode' Name='menu_system_code' PropertyName='Value' />
        <asp:Parameter Name="sub_menu_name" />
        <asp:Parameter Name="sub_menu_url" />
        <asp:Parameter Name="type_code" />
        <asp:Parameter Name="sub_menu_status" />
        <asp:SessionParameter Name="staff_code_create" SessionField="staff_code" />
        <asp:SessionParameter Name="staff_code_update" SessionField="staff_code" />
    </InsertParameters>
</asp:SqlDataSource>
